package m1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接140服务器
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");//wht6.cn
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
       Connection con = f.newConnection();//连接
        Channel c = con.createChannel();//通信通道

        //在rabbit服务器创建队列helloworld,已经存在不会重复创建
        c.queueDeclare("helloworld",false,false,false,null);



        //向helloworld队列发生消息
        //任何消息必须转成byte[]数组才能发送
        c.basicPublish("", "helloworld", null, "Hello World".getBytes());

        //断开连接
        c.close();
        con.close();
    }
}
